/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ddbadmin.admin;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 *
 * @author Roar
 */
public class ObjectServer {

    int port;
    Object objectToSend;

    public ObjectServer(int port, Object objectToSend) {
        this.port = port;
        this.objectToSend = objectToSend;
        try {
            ServerSocket objectServer = new ServerSocket(port);
            Socket socket = objectServer.accept();
            ObjectInputStream objectInput = new ObjectInputStream(socket.getInputStream());
            ObjectOutputStream objectOutput = new ObjectOutputStream(socket.getOutputStream());
            objectOutput.writeObject(objectToSend);
            objectOutput.flush();
            try {

                objectInput.close();
                objectOutput.close();
                socket.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
